#include <iostream>
#include <vector> // for vector
#include <queue> // for priority_queue

using namespace std;

class Solution {
public:
    vector<int> find_smallest_k(const vector<int>& nums, int k) {
        // 特殊情况处理
        int n = nums.size();
        if (k > n || k < 0) {
            cerr << "ERROR: k is invalid" << endl;
        }
        else if (k == n) {
            return nums;
        }
        else if (k == 0) {
            return vector<int>();
        }

        // 构建大根堆
        priority_queue<int> heap;
        
        for (const int& num : nums) {
            heap.push(num);
            if ((int)heap.size() > k) {
                heap.pop();
            }
        }

        vector<int> res(k, 0);
        int i = k - 1;
        while (!heap.empty()) {
            res[i--] = heap.top();
            heap.pop();
        }

        return res;
    }

    // for debug
    void print(const vector<int>& nums) {
        for (const int& num : nums) {
            cout << num << " ";
        }
        cout << endl;
    }

};

void test() {
    Solution s;

    int n;
    while (cin >> n) {
        vector<int> nums(n, 0);
        for (int i = 0; i < n; ++i) {
            cin >> nums[i];
        }

        int k;
        cin >> k;
        vector<int> res = s.find_smallest_k(nums, k);
        cout << "最小的" << k << "个元素为：" << endl;
        s.print(res);
    }
}

int main(void)
{
    test();
    return 0;
}

